// 最长回文子串， 双指针
let s = 'bcabad'

var lengthOfLongestSubstring = function (s) {
    if(s.length === 1) return s
    let maxRes = 0, maxStr = ''

    for (let i = 0; i < s.length; i++) {
        let str1 = palindrome(s, i, i) // 字符串中的第一项一定是回文
        let str2 = palindrome(s, i, i + 1)
    if(str1.length > maxRes) {
        maxRes = str1.length
        maxStr = str1
    }
    if(str2.length > maxRes) {
        maxRes = str2.length
        maxStr = str2
    }
}
    return maxStr
}

function palindrome(s, l, r) {
while(l >= 0 && r < s.length && s[l] == s[r]) {
    l--
    r++ 
}
return s.slice(l+1, r)
}